﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YXShop.BLL.Stocks;

namespace YXShop.Web.admin.stocks
{
    public partial class Order_List : System.Web.UI.Page
    {
        Order bllOrder = new Order();
        BLL.Store.Store bllStore = new BLL.Store.Store();
        BLL.Member.MemberAccount bllMemberAccount = new BLL.Member.MemberAccount();
        BLL.Admin.Administrators bllAdmin = new BLL.Admin.Administrators();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string where = "";
                this.lblList.Text = GetList(where);
            }
        }
        #region 绑定
        private string GetList(string where)
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage = bllOrder.GetList(where);
            table.AddHeadCol("", "<input id=\"chall\" type=\"checkbox\" onclick=\"SelectAll(chall)\" />全选");
            table.AddHeadCol("", "订单号");
            table.AddHeadCol("", "门店");
            table.AddHeadCol("", "订单时间");
            table.AddHeadCol("", "处理人");
            table.AddHeadCol("", "是否会员");
            table.AddHeadCol("", "会员名");
            table.AddHeadCol("", "操作");
            table.AddRow();
            if (dataPage.DataReader != null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();

                while (dataPage.DataReader.Read())
                {
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    Model.Stocks.Order orderModel = bllOrder.GetModelById(int.Parse(dataPage.DataReader["id"].ToString()));
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=\"" + dataPage.DataReader["id"].ToString() + "\" />");
                    table.AddCol(orderModel.Ordernum);
                    int stockid=int.Parse(dataPage.DataReader["storeid"].ToString());
                    Model.Store.Store storeModel = bllStore.GetModelById(stockid);
                    table.AddCol(storeModel.Storename);
                    table.AddCol(orderModel.Ordertime.ToString());
                    table.AddCol(bllAdmin.GetModel((int)orderModel.Adminid).Name);
                    table.AddCol(orderModel.isMember ? "是" : "否");
                    string member="非会员";
                    if (orderModel.Memberid > 0)
                    {
                        member = bllMemberAccount.GetModel((int)orderModel.Memberid).UserId;
                    }
                    table.AddCol(member);
                    table.AddCol(string.Format("<a href='#' onclick='Del({0})'>删除</a>", orderModel.Id));
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
        #endregion
    }
}